import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import path from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(), // 按需引入element
    vueJsx(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  build: {
    outDir: "my-test",
    target: "es2015",
    minify: "esbuild",
    chunkSizeWarningLimit: 2000,
    // lib: {
    //   entry: path.resolve(__dirname, "./src/packages/index.ts"),
    //   name: "my-test",
    //   fileName: (format) => `my-test.${format}.js`,
    // },
    lib: {
      entry: path.resolve(__dirname, "./src/login-tsx/login.tsx"),
      name: "my-login",
      fileName: (format) => `my-login.${format}.js`,
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ["vue"],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: "Vue",
        },
      },
    },
  },
});
